package com.jilefojing.beans.enums;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;

/**
 * 
 * @author 作者 jgshun
 * @date 创建时间 2016年07月19日 13时11分12秒
 */
public enum StatusEnumForPublish {

	/**
	 * (short) 1, "已发布"
	 */
	ALREADY_RELEASED((short) 1, "已发布"),
	/**
	 * (short) 2, "已下线"
	 */
	OFFLINE((short) 2, "已下线"),
	/**
	 * (short) 3, "待发布"
	 */
	PENDING_RELEASE((short) 3, "待发布");

	private short code;
	private String msg;

	private StatusEnumForPublish(short code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public short getCode() {
		return code;
	}

	public String getMsg() {
		return msg;
	}

	@Override
	public String toString() {
		if (this != null) {
			Map<String, Object> allMap = new HashMap<String, Object>();
			allMap.put("code", this.code);
			allMap.put("msg", this.msg);
			String result = JSONObject.toJSONString(allMap);
			result = result.replaceAll("\"", "'");
			return result;
		}
		return super.toString();
	}

	public static StatusEnumForPublish getStatusEnumByCode(short code) {
		for (StatusEnumForPublish _enum : StatusEnumForPublish.values()) {
			if (_enum.getCode() == code) {
				return _enum;
			}
		}
		return null;
	}
}
